package com.sikaryofficial.backend.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.sikaryofficial.backend.domain.entity.ArticleCategory;
import com.sikaryofficial.backend.mapper.ArticleCategoryMapper;
import com.sikaryofficial.backend.service.IArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 文章分类Service业务层处理
 *
 * @author qinjinyuan
 * @date 2024-04-10
 */
@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory> implements IArticleCategoryService {
    @Autowired
    private ArticleCategoryMapper articleCategoryMapper;

    @Override
    public Map<Long, ArticleCategory> getCategoryMap() {
        List<ArticleCategory> result = this.list(new LambdaQueryWrapper<ArticleCategory>()
                .eq(ArticleCategory::getDeletedVersion, 0L)
        );
        if (CollUtil.isEmpty(result)) {
            return Maps.newHashMap();
        }
        return result.stream()
                .collect(Collectors.toMap(ArticleCategory::getArticleCategoryId, Function.identity(), (k1, k2) -> k1));
    }
}
